package com.tnf.bc.bground.datasource.interceptor;

import com.tnf.bc.bground.datasource.properties.DataSourceParame;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.AsyncHandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class DataSourceInterceptor implements AsyncHandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
		//TODO
//		if (DataSourceParame.DS_NAME_LIST.contains(user.getCompany().getDeployGroup())) {
//			DynamicDataSourceContextHolder.setDataSourceType(user.getCompany().getDeployGroup());
//		}
		return true;
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		DynamicDataSourceContextHolder.clearDataSourceType();
	}

	@Override
	public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		DynamicDataSourceContextHolder.clearDataSourceType();
	}
}
